<?php
include("session.php");
include("config.php");

$row = prepare_edit(LEVEL_EDIT_PROJECT, LEVEL_CREATE_PROJECT, "edit_project.php", Rlang("project"), "project", $db, "maintime.php");
if (!$row)
   exit();

$id = 0;
$customerIsRetired = false;
if ($row != 0) {
   $id = $row['id'];
   $sql = "SELECT * FROM customer where id = ?";
   if (!$result = get_db_result($db, $sql, "i", $row['customer_id'])) {
      echo ($sql . " ");
      die(mysqli_error($db));
   }
   $crow = mysqli_fetch_array($result, MYSQLI_ASSOC);

   $customerIsRetired = $crow['retired'] != null;
   $readonly = $customerIsRetired  || $row['retired'] != null;
} else
   $readonly = false;
   
$fallback = "maintime.php";
$loc_entity = "Projekt";
$action = "write_project.php";
$fields = [
   ["name" => "name", "loc" => RLang("name"), "type" => "text", "limit" => 50],
   ["name" => "customer_id", "loc" => RLang("customer"), "type" => "selection", "sql" => "SELECT * FROM customer where retired is null"],
   ["name" => "created", "loc" => RLang("created"), "type" => "text", "readonly" => true],
];
include("itable_editor.php");
